type AddZero = (i: number) => string;
type FormatDate = (time?: Date) => string;

const addZero: AddZero = n => (n < 10 ? '0' : '') + n;
const formatDate: FormatDate = (time = new Date()) => {
    enum Time {
        year = time.getFullYear(),
        month = time.getMonth() + 1,
        data = time.getDate(),
        hours = time.getHours(),
        minutes = time.getMinutes(),
        seconds = time.getSeconds()
    }
    return `${Time.year}-${addZero(Time.month)}-${addZero(Time.data)} ${addZero(Time.hours)}:${addZero(Time.minutes)}:${addZero(Time.seconds)}`;
};

export default formatDate;